﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AgriculturalMachinery.Models
{
    public class NotifyViewModel<T> : List<T>
    {
        #region 通知(新闻)管理的分页代码
        public int NotifyPageIndex { get; private set; }
        public int NotifyPageSize { get; private set; }
        public int NotifyTotalCount { get; private set; }
        public int NotifyTotalPages { get; private set; }
        public IQueryable QueryNotify { get; private set; }

        public bool NotifyHasPreviousPage
        {
            get
            {
                return (NotifyPageIndex > 0);
            }
        }

        public bool NotifyHasNextPage
        {
            get
            {
                return (NotifyPageIndex + 1 < NotifyTotalPages);
            }
        }

        public NotifyViewModel(IQueryable<T> NotifySource, int NotifyPageIndex, int NotifyPageSize)
        {
            this.NotifyPageIndex = NotifyPageIndex;
            this.NotifyPageSize = NotifyPageSize;
            this.NotifyTotalCount = NotifySource.Count();
            this.NotifyTotalPages = (int)Math.Ceiling(NotifyTotalCount / (double)NotifyPageSize);
            QueryNotify = NotifySource.Skip(NotifyPageIndex * NotifyPageSize).Take(NotifyPageSize);
            
        }
        #endregion
    }
}
